﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jzy.BLL.Calendar
{
    /// <summary>
    /// 扩展DateTime的方法的类
    /// </summary>
    public static class DateTimeExtend
    {
        /// <summary>
        /// 获得当前时间的周一的日期
        /// </summary>
        /// <param name="dateTime"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public static DateTime GetMonday(this DateTime dateTime, DateTime time)
        {
            int iDaysOfWeek = (int)time.DayOfWeek;
            DateTime monday;
            if (iDaysOfWeek == 0)
            {
                monday = time.AddDays(-6);
                monday = new DateTime(monday.Year, monday.Month, monday.Day);
            }
            else
            {
                monday = time.AddDays(-iDaysOfWeek + 1);
                monday = new DateTime(monday.Year, monday.Month, monday.Day);
            }
            return monday;
        }
    }
}
